package com.steadyoung.modelapp;

import android.content.Context;
import android.support.multidex.MultiDex;
import android.support.multidex.MultiDexApplication;

import com.steadyoung.modelapp.util.common.CrashHandler;
import com.steadyoung.modelapp.util.common.Utils;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;

/**
 * Created by Administrator on 2017/9/7.
 * Email : steadyoung@foxmail.com
 * Auth  : wayne
 * Desc  : TODO
 */
public class MyApplication extends MultiDexApplication {
    private static Context app;

    @Override
    public void onCreate() {
        super.onCreate();
        app = getApplicationContext();
        MultiDex.install(app);
        Utils.init(this);
        CrashHandler.getInstance().init(this);

        //rxjava+retrofit初始化
//        RxRetrofitApp.init(this, HttpTestService.SERVICE_URL);

        //GreenDao的初始化
//        GreenDaoManager.getInstance();
        refWatcher = setupLeakCanary();
    }

    public static Context getApp() {
        return app;
    }

    /**内存检测工具对象*/
    private static RefWatcher refWatcher;

    /**获取内存检测工具对象*/
    public static RefWatcher getRefWatcher(){
        if(refWatcher == null ) refWatcher = RefWatcher.DISABLED;
        return refWatcher;
    }

    /**初始化内存检测工具**/
    protected RefWatcher setupLeakCanary() {
        if (LeakCanary.isInAnalyzerProcess(this)) {
            return RefWatcher.DISABLED;
        }
        return LeakCanary.install(this);
    }
}
